package 剑指offer.demo3;
//https://www.nowcoder.com/questionTerminal/a9d0ecbacef9410ca97463e4a5c83be7

/**
 * 把左右子树交换后，依次递归的继续处理左树和右树的子树
 */
public class 二叉树的镜像 {
    public TreeNode Mirror (TreeNode pRoot) {
        //合法性判断
        if (pRoot == null)
            return null;
        //将根节点左右子树互换
        TreeNode cur = pRoot.left;
        pRoot.left = pRoot.right;
        pRoot.right = cur;
        //递归的处理其左右子树
        Mirror(pRoot.left);
        Mirror(pRoot.right);
        return pRoot;
    }

    //题目给定二叉树
    public class TreeNode {
    int val = 0;
    TreeNode left = null;
    TreeNode right = null;
    public TreeNode(int val) {
      this.val = val;
    }
  }

}
